#pragma once

#include "SharedObjectPtr.h"

class RObject;

template <typename InterfaceType>
class TSharedInterfacePtr
{

protected:
    InterfaceType* Interface=nullptr;
    TSharedObjectPtr<RObject> Object;

public:
    TSharedInterfacePtr()=default;

    TSharedInterfacePtr(std::nullptr_t )
    {
    };

    TSharedInterfacePtr(InterfaceType* InInterface)
    {
        if(InInterface)
        {
            Interface=InInterface;
            Object=InInterface->_GetObjectOfInterface();
        }
    };

    TSharedInterfacePtr(const TSharedInterfacePtr& Other)
    {
        Interface=Other.Interface;
        Object=Other.Object;
    };

    TSharedInterfacePtr& operator=(const TSharedInterfacePtr& Other)
    {
        Interface=Other.Interface;
        Object=Other.Object;
        return *this;
    };

    TSharedInterfacePtr& operator=(InterfaceType* InInterface)
    {
        Interface=InInterface;
        Object=InInterface->_GetObjectOfInterface();
        return *this;
    };

    InterfaceType* Get() const
    {
        return Interface;
    };

    InterfaceType* operator->() const
    {
        return Interface;
    };

    TSharedObjectPtr<RObject> GetObject() const
    {
        return Object;
    };

    operator bool() const
    {
        return Object.IsValid();
    };

    bool operator==(const TSharedInterfacePtr& Other) const
    {
        return Interface==Other.Interface;
    };

    bool operator==(InterfaceType* OtherInterface) const
    {
        return Interface==OtherInterface;
    };

    
};